package com.vf.cloud.server.colony;

import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.kit.StrKit;
import com.vf.cloud.server.colony.server.NServer;

public class NodeServer {
	
	public static void main(String[] args) {
		NodeServer.getInstance().run();
	}
	
	private static volatile NodeServer INSYANCE;

	private NServer server;

	private NodeServer() {
		server = new NServer();
	}

	public static NodeServer getInstance() {
		if (null == INSYANCE) {
			synchronized (NodeServer.class) {
				if (null == INSYANCE) {
					INSYANCE = new NodeServer();
				}
			}
		}
		return INSYANCE;
	}

	public void run() {
		if (server != null) {
			server.run();
		}
	}

	public void restart() {
		if (server != null) {
			server.restart();
		}
	}

	public void stop() {
		if (server != null) {
			server.stop();
		}
	}

	public int getStatus() {
		if (server != null) {
			return server.getStatus();
		}
		return -1;
	}

	public boolean verify(JSONObject object) {

		if (object == null) {
			return false;
		}

		if (!object.containsKey("signalingIP") || StrKit.isBlank(object.getString("signalingIP"))) {
			return false;
		}
		if (!object.containsKey("signalingInnerIP") || StrKit.isBlank(object.getString("signalingInnerIP"))) {
			return false;
		}
		if (!object.containsKey("signalingPort") || StrKit.isBlank(object.getString("signalingPort"))) {
			return false;
		}
		if (!object.containsKey("signalingInnerPort") || StrKit.isBlank(object.getString("signalingInnerPort"))) {
			return false;
		}

		return true;
	}
	
	public void send(Map<String, Object> data) {
	}

}
